#!/bin/bash

set -v

if [[ "$DOCKER_REPO" == "index.docker.io/openzipkin/zipkin" ]]; then
  echo Pushing zipkin-slim and test images
  IFS=',' read -ra TAGS <<< "$DOCKER_TAG"
  for tag in ${TAGS[@]}; do
    docker push "openzipkin/zipkin-slim:$tag"
    docker push "openzipkin/zipkin-ui:$tag"

    for collector in kafka; do
      docker push "openzipkin/zipkin-${collector}:$tag"
    done

    for storage in cassandra elasticsearch6 elasticsearch7 mysql; do
      docker push "openzipkin/zipkin-${storage}:$tag"
    done
  done

  if [[ "$DOCKER_TAG" == "master" ]]; then
    # We repush the builder image on master push, not on release pushes.
    echo Building zipkin-builder
    docker build -f "$DOCKERFILE_PATH" -t openzipkin/zipkin-builder --target zipkin-builder .

    echo Pushing zipkin-builder
    # zipkin-builder is just a cache of maven / npm dependencies, there's no need to version it
    # with docker tags.
    docker push openzipkin/zipkin-builder
  fi
fi
